/*
 * @Author: szx
 * @Date: 2021-12-12 19:12:57
 * @LastEditTime: 2021-12-12 19:46:32
 * @Description:
 * @FilePath: \leetcode\100-199\150\150.js
 */
/**
 * @param {string[]} tokens
 * @return {number}
 */
var evalRPN = function (tokens) {
    const stack = [];
    const r = /^-?\d+$/;
    for (let str of tokens) {
        if (r.test(str)) {
            stack.push(parseInt(str));
        } else if (str == '+') {
            stack.push(stack.pop() + stack.pop());
        } else if (str == '-') {
            stack.push(-stack.pop() + stack.pop());
        } else if (str == '*') {
            stack.push(stack.pop() * stack.pop());
        } else if (str == '/') {
            let tmp = stack.pop();
            stack.push(parseInt(stack.pop() / tmp));
        }
    }
    return stack[0];
};
console.log(evalRPN(["4","13","5","/","+"]));
